from django.shortcuts import render_to_response
from django.template  import loader, Context
from django.template  import RequestContext
from django.contrib   import auth
from django.core      import serializers
from django.http      import HttpResponse
from django.http      import HttpResponseRedirect
from django.db        import transaction

from inv.entity.models  import *
from inv.utils.db       import *
from inv.utils.errors   import *
from inv.utils.trace    import *

import time, base64, datetime

def combo(request, cls_id, met_id) :
   if request.method == 'POST':
      cc = request.POST['COMBO_CONTENT']
      ret = Combo_Content(cls_id=cls_id, met_id=met_id, val=cc).add()
      return render_to_response('ajax_response.json', ret)
   else : 
      pass

def add(request, cls_id) :
   if request.method == 'POST' :
      met_names = []
      vals = []
      for key in request.POST :
         met_names.append(key)    
         vals.append(request.POST[key])
         ENT.debug("VIEW : add : " + key + "=" + request.POST[key]) 
      ret = Object(cls_id=cls_id).add(met_names=met_names, vals=vals)
      return render_to_response('ajax_response.json', ret)

def add_bulk(request, cls_id) :
   if request.method == 'POST' :
      ret = {'rc' : 0, 'rm' : 'hi'}
      ENT.debug(request)
      file = request.FILES['FILE']
      dd = request.POST['DUE_DATE']
      desc = request.POST['DESC']
      #ret = Bulk_Add(cls_id = cls_id, fname = file.name, due_date = dd, desc = desc).add(file=file)
      return render_to_response('ajax_response.json', ret)

